package com.hkts.beltweigher.salve.service.serviceimpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hkts.beltweigher.opc.DataCache;
import com.hkts.beltweigher.salve.entity.EastBeltscalesMinitue;
import com.hkts.beltweigher.salve.mapper.EastBeltscalesMinitueMapper;
import com.hkts.beltweigher.salve.service.IEastBeltscalesMinitueService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author hml
 * @since 2024-11-18
 */
@Service
@Transactional
public class EastBeltscalesMinitueServiceImpl extends ServiceImpl<EastBeltscalesMinitueMapper, EastBeltscalesMinitue> implements IEastBeltscalesMinitueService {


    @Autowired
    private EastBeltscalesMinitueMapper eastBeltscalesMinitueMapper;

    @Override
    public IPage<EastBeltscalesMinitue> selectPage(Page<EastBeltscalesMinitue> page, EastBeltscalesMinitue eastBeltscalesMinitue) {
        QueryWrapper<EastBeltscalesMinitue> query = Wrappers.query();
        return eastBeltscalesMinitueMapper.selectPage(page, query);
    }


    @Override
    public List<EastBeltscalesMinitue> selectList(EastBeltscalesMinitue eastBeltscalesMinitue) {
        QueryWrapper<EastBeltscalesMinitue> query = Wrappers.query();
        return eastBeltscalesMinitueMapper.selectList(query);
    }

    @Override
    public List<EastBeltscalesMinitue> selectEastBeltsCalesMinitueListGt(Integer id) {
        QueryWrapper<EastBeltscalesMinitue> query = Wrappers.query();
        query.lambda().gt(EastBeltscalesMinitue::getId,id);
        return eastBeltscalesMinitueMapper.selectList(query);
    }

    @Override
    public void handlerMinituedata() {

        EastBeltscalesMinitue minute=new EastBeltscalesMinitue();
        minute.setDate(LocalDate.now());
        minute.setTime(LocalTime.now());
        minute.setDatetime(LocalDateTime.now());
        minute.setInstantaneousTraffic1(Float.parseFloat(DataCache.ALLCACHE.get("6").toString()));
        minute.setInstantaneousTraffic2(Float.parseFloat(DataCache.ALLCACHE.get("7").toString()));
        minute.setInstantaneousTraffic3(Float.parseFloat(DataCache.ALLCACHE.get("8").toString()));
        minute.setInstantaneousTraffic4(Float.parseFloat(DataCache.ALLCACHE.get("9").toString()));
        minute.setInstantaneousTraffic5(Float.parseFloat(DataCache.ALLCACHE.get("10").toString()));
        eastBeltscalesMinitueMapper.insert(minute);
    }
}
